﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Net.Core;
using Net.IService;
using Net.Model.Entities.Expression;
using Net.Model.Entities.User;
using Net.Model.FromBody;
using Net.Model.ViewModels.UI;
using Net.Service;
using SqlSugar;

namespace WebApi.Controllers
{
    [ApiController]
    [Route("Api/[controller]/[action]")]
    [Authorize]
    public class SysUserController : ControllerBase
    {
        private readonly ISysUserServices _sysUserServices;
        public SysUserController(ISysUserServices sysUserServices)
        {
            this._sysUserServices = sysUserServices;
        }


        [HttpGet]
        public async Task<WebApiCallBack> GetUserInfo()
        {
            var jm = new WebApiCallBack() { status = true };
            var user = await _sysUserServices.QueryByIdAsync(1);
            if (user == null)
            {
                jm.status = false;
                jm.msg = "用户信息获取失败";
                jm.code = 14007;
                return jm;
            }
            jm.data = new
            {
                user.id,
                user.userName,
                user.passWord
            };
            return jm;
        }

        [HttpGet]
        public async Task<WebApiCallBack> GetUserCache()
        {
            var jm = new WebApiCallBack() { status = true };
            var user = await _sysUserServices.QueryByIdAsync(1);
            //var user = await _userService.QueryByIdAsync(1);
            if (user == null)
            {
                jm.status = false;
                jm.msg = "用户信息获取失败";
                jm.code = 14007;
                return jm;
            }
            jm.data = new
            {
                user.id,
                user.userName,
                user.passWord
            };
            return jm;
        }


    }
}
